﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/// <summary>
/// 技能状态组件
/// </summary>
public class SkillStatusComponent : ECSMomentCompoentBase
{
    /// <summary>
    /// 技能位于哪一状态（一段/二段/三段）
    /// </summary>
    public SkillStatusEnum m_skillStatus = SkillStatusEnum.None;
    /// <summary>
    /// 当前技能进行了多久
    /// </summary>
    public int m_skillTime = 0;
    /// <summary>
    /// 持续性伤害伤害间隔剩余（还有多久到下一次）
    /// </summary>
    public int m_skillTrigerTimeSpace = 0;

    /// <summary>
    ///技能开始造成伤害判定
    /// </summary>
    public bool m_isHit = false;

    /// <summary>
    /// 是否更改了技能当前状态（一段，二段，三段）
    /// </summary>
    public bool m_isEnter = false;

    /// <summary>
    /// 下一段技能是否释放
    /// </summary>
    public bool isClick = false;

    #region 当前技能只有一段时
    /// <summary>
    /// 当前技能是否只有一段
    /// </summary>
    public bool onlyBefore;
    /// <summary>
    /// 单次伤害是否已完毕（仅单次伤害时使用）
    /// </summary>
    public bool m_isTriggerSkill = false;
    #endregion

    /// <summary>
    /// 为1时一段开始，为2时2段开始
    /// </summary>
    public int skillCkick;

    /// <summary>
    /// 第二段最大等待时长(一段运行加二段等待)
    /// </summary>
    public float BMaxWaiteTime
    {
        get { return m_currentSkillData.BWaitMaxTime; }
    }


    /// <summary>
    /// 技能朝向
    /// </summary>
    public SyncVector3 skillDir = new SyncVector3();
    /// <summary>
    /// 当前技能数据
    /// </summary>
    public SkillData m_currentSkillData
    {
        set
        {
            //如果当前技能正在进行中，不允许修改
            if (m_skillStatus==SkillStatusEnum.Before||m_skillStatus==SkillStatusEnum.Current)
            {
                return;
            }

            //更改当前技能
            m_currentSkillData = value;
            //技能未触发
            m_isTriggerSkill = false;

            //未更改技能状态（当前位于几段改变）
            m_isEnter = false;
            //技能是否只有一段
            onlyBefore = value.OnlyBefore;
            //技能位于一段
            m_skillStatus = SkillStatusEnum.Before;
            skillCkick = 1;//一段开始
        }
        get { return m_currentSkillData; }

    }
    /// <summary>
    /// 技能数据
    /// </summary>
    public List<SkillData> m_skillList = new List<SkillData>();

    //表现用
    /// <summary>
    /// 当前特效持续了多少时间
    /// </summary>
    public int FXTimer = 0;
    public bool isTriggerFX;
    public override ECSMomentCompoentBase DeepCopy()
    {
        SkillStatusComponent sc = new SkillStatusComponent();

        sc.ID = ID;
        sc.Entity = Entity;
        sc.Frame = Frame;

        sc.m_skillStatus = m_skillStatus;

        sc.m_skillTime = m_skillTime;
        sc.m_skillTrigerTimeSpace = m_skillTrigerTimeSpace;

        sc.m_isHit = m_isHit;
        sc.m_isEnter = m_isEnter;
        sc.m_isTriggerSkill = m_isTriggerSkill;
        sc.skillDir = skillDir;

        if (m_currentSkillData != null)
        {
            sc.m_currentSkillData = m_currentSkillData.DeepCopy();
        }

        for (int i = 0, j = m_skillList.Count; i < j; i++)
        {
            sc.m_skillList.Add(m_skillList[i].DeepCopy());
        }

        return sc;
    }
    /// <summary>
    /// 获取指定id的技能数据
    /// </summary>
    /// <param name="ID"></param>
    /// <returns></returns>
    public SkillData GetSkillData(string ID)
    {
        for (int i = 0, j = m_skillList.Count; i < j; i++)
        {
            if (m_skillList[i].m_skillID == ID)
            {
                return m_skillList[i];
            }
        }
        throw new Exception("加载技能数据失败，无此id技能" + ID);
    }
}
/// <summary>
/// 技能位于状态枚举
/// </summary>
public enum SkillStatusEnum
{
    /// <summary>
    /// 无
    /// </summary>
    None,
    /// <summary>
    /// 前段状态
    /// </summary>
    Before,
    /// <summary>
    /// 中段状态
    /// </summary>
    Current,
  
    /// <summary>
    /// 结束
    /// </summary>
    Finish,
}

